package home.contaduria.service.impl;

import home.contaduria.dao.ClientDao;
import home.contaduria.domain.Client;
import home.contaduria.service.ClientService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service("clientService")
public class ClientServiceImpl implements ClientService {

	private ClientDao clientDao;

	@Autowired
	public void setClientDao(ClientDao clientDao) {
		this.clientDao = clientDao;
	}

	@Override
	@Transactional
	public void createClient(Client client) {
		clientDao.create(client);
	}

	@Override
	@Transactional(readOnly = true)
	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
		return clientDao.loadUserByUsername(username);
	}

}
